package com.yunf.zookeeper;

import org.apache.zookeeper.KeeperException;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yunf
 * @create 2022-03-24 14:10
 */
public class MainDemo {

    public static void main(String[] args) throws Exception {
        BaseZookeeper zookeeper = new BaseZookeeper();
        zookeeper.connectZookeeper("10.0.101.235:2181");
        final List<String> childrens = zookeeper.getChildren("/config/jcmro");
        List<doMain> collect = childrens.stream().map(str -> {
            doMain doMain = new doMain();
            String path = "/config/jcmro/" + str;
            doMain.setPath(path);
            byte[] data = null;
            try {
                data = zookeeper.getData(path);
            } catch (Exception e) {
                e.printStackTrace();
            }
            doMain.setData(data);
            return doMain;
        }).collect(Collectors.toList());
        zookeeper.closeConnection();


        BaseZookeeper zookeeper1 = new BaseZookeeper();
        zookeeper1.connectZookeeper("10.0.54.11:2181");
        collect.stream().forEach( en->{
            try {
                String node = zookeeper1.createNode(en.getPath(), en.getData());
            } catch (Exception e) {
                e.printStackTrace();
            }

        });
        zookeeper1.closeConnection();
        System.out.println("复制完毕");

    }
}
